//暴露mixins对象
// import {sksCacheTableMixin} from "sks-plugin-el-erp/lib/sks-cache-table";

import {
    deleteFromVueVirtualUUID,
    generateUUID,
    getIndexByUUIDTable,
    initRowVueVirtualUUID,
    isNullOrUndefined,
    mergeFromObject
} from "./core";
import {addOrUpdateRow, deleteRow, dictFormatOnElTableColumn} from "./sks-app-utils";
import {newSksTable} from "./sks-model-utils";

export const sksCacheTableMixin = {
    data(){
        return{
            allLoading: false,

            mainTable: {
                dataType: 1,
                list:[],

                loading: false,
                elementLoadingText: '拼命加载中',

                //当前存在单选项,true 禁用
                single : true,
                //当前存在多选项,true 禁用
                multiple : true,
                //点击的行
                currentRow: {},
                //勾选的行ID集合
                ids:[],
                // 勾选的行
                selection: [],

                //显示缓存列,展示修改/删除/新增
                showCacheChangeFlagColumn: false,

                showTable: true,

                showAllColumnButton: false,
                showAllColumn: false,

                showSearchButton: false,
                showSearch: true,

                uuid: generateUUID(),
                //el-table 中的主键属性名,不设置拖动排序将不会刷新排序
                rowKey: 'vueVirtualUUID',
                //拖动排序,需要在 el-table 设置 rowKey 属性名称
                dragSort: false,
                //拖动排序字段名
                dragSortPropName: 'sort',
                dragSortTableTmp: undefined,

                //true: 启用删除缓存,删除的行会以横线展示,false: 将会直接删除行,若是为false,删除的行需在服务端判断不存在后删除
                deleteCacheHorizontalLine: true,

                //默认展开所有行
                defaultExpandAll: false,

                //表格高度
                tableHeight: undefined,
            },

            //字典数据都放这里
            dictDataMap: new Map(),
        }
    },
    beforeCreate(){
        console.log("混入的beforeCreated");

    },
    created() {
        console.log("sks-page.created")
        this.sksInit();
    },
    methods: {
        sksInit(){
            this.mainTable=mergeFromObject(newSksTable(),this.mainTable,this.initMainTableParam())
            // getAutumnAppPropList(this.mainTable)
            this.getDictData()
            this.mainTable.linkMap={
                dictDataMap: this.dictDataMap,
                dictTypeConfList: this.initDictTypeConf(),
            }
        },
        getDictData(){
            let dictTypeList = this.initDictTypeConf();
            // getDictDataSetDictDataMap({
            //     dictDataMap: this.dictDataMap,
            //     dictTypeList: dictTypeList,
            // })
        },
        /**
         * 需要获取的字典
         * @return []
         [
         {
                        prop: 'processStatus',
                        dictType: 'status',
                       //字典的数据类型,如果为 Number 会将字典数据转换为数字类型
                        dictValueType: 'Number'
                      }
         ]
         */
        initDictTypeConf(){
            return []
        },
        dictFormatOnElTableColumn(row, column){
            return dictFormatOnElTableColumn({
                row: row,
                column: column,
                mainTable: this.mainTable,
            })
        },
        /**
         * 初始化 mainTable 的一些值
         * @return {}  例如: {showSearchButton: true} 显示工具栏的搜索放大镜
         */
        initMainTableParam(){
            return {}
        },
        emitChangeSksTable(){
            this.$emit('input',this.mainTable.list)
            this.$emit('change',this.mainTable.list)
        },
        addOrUpdateRow(row){
            addOrUpdateRow({row:row,mainTable: this.mainTable,_this:this})
        },
        deleteRow(row){
            deleteRow({row:row,mainTable: this.mainTable})
        },
    },
}
